package com.xiaobo.framework.endpoint;

import com.xiaobo.framework.api.request.LaunchOrderRequest;
import com.xiaobo.framework.api.response.OrderListResponse;
import com.xiaobo.framework.common.exception.BizException;
import com.xiaobo.framework.service.order.OrderSerice;
import io.swagger.annotations.*;
import lombok.extern.slf4j.Slf4j;
import org.springframework.http.MediaType;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

import javax.validation.Valid;
import java.util.List;
import java.util.Optional;

/**
 * @author: <a href="get_xiaobo@163.com">Josh_Xu</a>
 * @description:
 * @create: 2020-08-18 13:35
 **/
@Slf4j
@RestController
@RequestMapping(value = "/order-api")
@Api(tags = "订单模块接口")
public class OrderEndpoint {

    private final OrderSerice orderSerice;

    public OrderEndpoint(OrderSerice orderSerice) {
        this.orderSerice = orderSerice;
    }

    @ApiOperation(value = "发起订单", produces = MediaType.APPLICATION_JSON_VALUE, response = LaunchOrderRequest.class)
    @ApiResponses({
            @ApiResponse(code = 200, message = "查询成功"),
            @ApiResponse(code = 500, message = "服务器异常")
    })
    @PostMapping(value = "/launch-order", produces = MediaType.APPLICATION_JSON_VALUE)
    ResponseEntity<?> launchOrder(@ApiParam(value = "订单实体") @Valid @RequestBody LaunchOrderRequest order) {
        try {
            Optional.ofNullable(order).orElseThrow(() -> new RuntimeException("消息内容为空"));
        } catch (BizException ex) {
            log.error("消息错误", ex);
        }
        return ResponseEntity.ok().build();
    }

    @ApiOperation(value = "撤销订单", produces = MediaType.APPLICATION_JSON_VALUE, response = Object.class)
    @ApiResponses({
            @ApiResponse(code = 200, message = "查询成功"),
            @ApiResponse(code = 500, message = "服务器异常")
    })
    @DeleteMapping(value = "/revoke-order", produces = MediaType.APPLICATION_JSON_VALUE)
    ResponseEntity<?> revokeOrder(@ApiParam(value = "订单id") @RequestParam(value = "orderId") String orderId) {
        try {

        } catch (BizException ex) {
            log.error("消息错误", ex);
        }
        return ResponseEntity.ok().build();
    }

    @ApiOperation(value = "订单列表", produces = MediaType.APPLICATION_JSON_VALUE, response = Object.class)
    @ApiResponses({
            @ApiResponse(code = 200, message = "查询成功"),
            @ApiResponse(code = 500, message = "服务器异常")
    })
    @GetMapping(value = "/order-list", produces = MediaType.APPLICATION_JSON_VALUE)
    ResponseEntity<?> orderList(@ApiParam(value = "订单种类") @RequestParam(value = "orderType") String orderType) {
        try {
            List<OrderListResponse> list = this.orderSerice.orderList(orderType);
            return ResponseEntity.ok(list);
        } catch (BizException ex) {
            log.error("消息错误", ex);
        }
        return ResponseEntity.ok().build();
    }

    @ApiOperation(value = "订单种类", produces = MediaType.APPLICATION_JSON_VALUE, response = Object.class)
    @ApiResponses({
            @ApiResponse(code = 200, message = "查询成功"),
            @ApiResponse(code = 500, message = "服务器异常")
    })
    @PostMapping(value = "/order-type-list", produces = MediaType.APPLICATION_JSON_VALUE)
    ResponseEntity<?> orderTypeList(@ApiParam(value = "订单种类") @RequestParam(value = "orderType") String orderType) {
        try {

        } catch (BizException ex) {
            log.error("消息错误", ex);
        }
        return ResponseEntity.ok().build();
    }


}
